package com.adcc.loadsheet.monitor.task;

import com.adcc.aoc.devLib.common.log.Log;
import com.adcc.loadsheet.monitor.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class MonitorTask {

    @Autowired
    private MonitorService service;

    @Scheduled(cron = "${monitorCron}")
    public void monitorBGS() {
        try {
            Log.info(MonitorTask.class, "execute BGS monitor task begin");
            service.monitorBGS();
            Log.info(MonitorTask.class, "execute BGS monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorBGS() error", ex);
        }
    }

    @Scheduled(cron = "${monitorCron}")
    public void monitorDatabase() {
        try {
            Log.info(MonitorTask.class, "execute Database monitor task begin");
            service.monitorDatabase();
            Log.info(MonitorTask.class, "execute Database monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorDatabase() error", ex);
        }
    }

    @Scheduled(cron = "${monitorCron}")
    public void monitorMQ() {
        try {
            Log.info(MonitorTask.class, "execute MQ monitor task begin");
            service.monitorMQ();
            Log.info(MonitorTask.class, "execute MQ monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorMQ() error", ex);
        }
    }

    @Scheduled(cron = "${monitorCron}")
    public void monitorAppUpload() {
        try {
            Log.info(MonitorTask.class, "execute appUpload monitor task begin");
            service.monitorAppUpload();
            Log.info(MonitorTask.class, "execute appUpload monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorAppUpload() error", ex);
        }
    }

    @Scheduled(cron = "${monitorCron}")
    public void monitorAirInfo() {
        try {
            Log.info(MonitorTask.class, "execute airInfo monitor task begin");
            service.monitorAirInfo();
            Log.info(MonitorTask.class, "execute airInfo monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorAirInfo() error", ex);
        }
    }

    @Scheduled(cron = "${monitorCron}")
    public void monitorMsgUpCenter() {
        try {
            Log.info(MonitorTask.class, "execute msgUpCenter monitor task begin");
            service.monitorMsgUpCenter();
            Log.info(MonitorTask.class, "execute msgUpCenter monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorMsgUpCenter() error", ex);
        }
    }

    @Scheduled(cron = "${monitorCron}")
    public void monitorWebsite() {
        try {
            Log.info(MonitorTask.class, "execute website monitor task begin");
            service.monitorWebsite();
            Log.info(MonitorTask.class, "execute website monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorWebsite() error", ex);
        }
    }

    @Scheduled(cron = "${monitorCron}")
    public void monitorForwarder() {
        try {
            Log.info(MonitorTask.class, "execute forwarder monitor task begin");
            service.monitorForwarder();
            Log.info(MonitorTask.class, "execute forwarder monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorForwarder() error", ex);
        }
    }

    /**
     * [2024-6-26：张丽娟]
     * 当监控程序使用的MySQL数据库异常（MySQL异常仅影响监控系统“日志查询”功能，不影响舱单业务），
     * 则系统弹出如下告警提示“MySQL服务异常”
     * 用户点击“确定”按钮，关闭告警弹框和声音告警。关闭后，如果系统有新的故障，则再次弹出告警提示并进行声音播报。
     * 未确认的告警弹窗，即使MySQL恢复正常，系统不自动关闭弹窗和声音告警提醒。
     * 声音告警播报内容为“机场地服监控-MySQL服务严重告警，请及时处理！”。
     */
    @Scheduled(cron = "${monitorCron}")
    public void monitorMysql() {
        try {
            Log.info(MonitorTask.class, "execute monitorMysql monitor task begin");
            service.monitorMysql();
            Log.info(MonitorTask.class, "execute monitorMysql monitor task end");
        } catch (Exception ex) {
            Log.error(MonitorTask.class, "monitorMysql() error", ex);
        }
    }

}
